<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="JS/bootstrap-3.3.7/css/bootstrap.min.css"/>
    <script src="JS/jquery-3.5.0.min.js"></script>
    <script src="JS/bootstrap-3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
    <div class="container" id="vue">
        <!-- Button trigger modal -->
        <button type="button" onclick="showBOX()" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
            分享
        </button>
        <!-- Modal -->
        <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">分享文件</h4>
                    </div>
                    <div class="modal-body">
                        <div class="submitBox" hidden>
                            <div>
                                提取码生成形式：
                                <div>
                                    <label class="radio-inline">
                                        <input type="radio" name="inlineRadioOptions" id="inlineRadio1" v-model="model.code" value="" v-on:click="hide()"> 系统子生成提取码
                                    </label>
                                </div>
                                <div>
                                    <label class="radio-inline">
                                        <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="custom" v-on:click="show()"> 自定义提取码
                                        <input type="text" hidden class="input-text" v-model="model.code"><p></p>
                                    </label>
                                </div>
                                <div><p></p></div>
                            </div>
                            <div>
                                有效期：&emsp;&emsp;&emsp;&emsp;
                                <label class="radio-inline">
                                    <input type="radio" name="inlineRadioOptions1" id="inlineRadio4" v-model="model.aging" value="forever" >永久有效
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="inlineRadioOptions1" id="inlineRadio5" v-model="model.aging" value="30"> 30天
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="inlineRadioOptions1" id="inlineRadio6" v-model="model.aging" value="7"> 7天
                                </label>
                                <label class="radio-inline">
                                    <input type="radio" name="inlineRadioOptions1" id="inlineRadio7" v-model="model.aging" value="1"> 1天
                                </label>

                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary" v-on:click="submit()" data-target="#myModal1"data-toggle="modal" >确定</button>
                    </div>
                    <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="myModalLabel1">Modal title</h4>
                                </div>
                                <div class="modal-body">
                                    链接：<input type="text" v-model="model.link">
                                    提取码：<input type="text"v-model="model.code">
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

</body>
</html>
<script>
    function showBOX(){
        $(".submitBox").show()
    }
    let vm=new Vue({
        el:'#vue',
        data(){
            return{
                model:{
                    code:"",
                    aging:"",
                    fileID:555,
                    userID:1,
                    link:"",
                }
            }
        },
        methods:{
            show:function (){
                $(".input-text").show();
                this.code=""
            },
            hide:function (){
                $(".input-text").hide();
            },
            submit:function (){
	            console.log(this.model.code)
	            let codeVal = this.model.code;
	            let agingVal = this.model.aging;
	            let fileIdVal = this.model.fileID;
	            let userIdVal = this.model.userID;
	            if(agingVal == "") {
		            alert("未选择有效期")
		            location.reload()
		            return;
	            }
	            if(codeVal != "") {
		            if(codeVal.length != 4) {
			            alert("填写的提取码应为4位数")
			            location.reload()
			            return;
		            }
	            }
	            let message = JSON.stringify({codeVal, agingVal, fileIdVal, userIdVal});
	            let link;
	            let code;
	            $.ajax({
		            contentType: 'application/json; charset=UTF-8',
		            type: "post",
		            data: message,
		            url: "http://localhost:8080/netdisc/share/share/link",
		            async: false,
		            success: function(resp) {
			            let parse = JSON.parse(resp);
			            code = parse.data.verifyCode;
			            link = parse.data.url;
		            }
	            })
                this.$set(this.model,"code",code)
                this.$set(this.model,"link",link)
            }
        },
    });
</script>